//
//  BaseViewController.m
//  quanminzhekou
//
//  Created by zxl on 15/1/7.
//  Copyright (c) 2015年 zhongqinglongtu. All rights reserved.
//

#import "BaseViewController.h"
#import <objc/runtime.h>

@implementation BaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    TabBarViewController* controller = (TabBarViewController*)[UIApplication sharedApplication].keyWindow.rootViewController;
    objc_setAssociatedObject(self, @selector(tabBarController), controller, OBJC_ASSOCIATION_RETAIN);
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self.tabBarController setTabBarHidden:NO animated:YES];
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    if (!self.tabBarController.tabBar.isNaviRootControllerChange) {
        [self.tabBarController setTabBarHidden:YES animated:YES];
    } else {
        self.tabBarController.tabBar.isNaviRootControllerChange = NO;
    }
}

- (void)viewDidDisappear:(BOOL)animated {
    [super viewDidDisappear:animated];
}

- (TabBarViewController*)tabBarController {
    TabBarViewController *tBController = objc_getAssociatedObject(self, @selector(tabBarController));
    
    if (!tBController) {
        tBController = (TabBarViewController*)[UIApplication sharedApplication].keyWindow.rootViewController;
    }
    
    return tBController;
}

@end
